#ifndef SPRITEMANAGER_HPP
#define SPRITEMANAGER_HPP

#include <map>
#include <string>

#include <SFML/Graphics.hpp>

class CenteredSprite{
public:
    sf::Image image;
    int centerX;
    int centerY;

    CenteredSprite(){};

    CenteredSprite(sf::Image * img,int x, int y){
        image = sf::Image(*img);
        centerX = x; centerY = y;
    };
    sf::Image * getImage(){
        return &image;
    }
    int getCenterX(){
        return centerX;
    }
    int getCenterY(){
        return centerY;
    }
};

class SpriteManager
{
    struct SpriteParam
    {
        std::string name;
        int angle;

        std::string completeIdName;

        SpriteParam(const std::string& spriteName, int angle);

        const std::string& getCompleteName()const { return completeIdName; }
    };

    struct SpriteParamComp
    {
        bool operator() (const SpriteParam& sp1, const SpriteParam& sp2)const
        {
            return sp1.getCompleteName() < sp2.getCompleteName();
        }
    };

    private:

        std::map<std::string, CenteredSprite> m_bank;

        std::map<SpriteParam, sf::Sprite, SpriteParamComp> m_bucket;

        bool loadSpriteFile(const std::string& fileName,int,int);

    public:
        SpriteManager();
        ~SpriteManager();

        bool loadSprite(const std::string& fileName,int,int,bool mipmap);
        bool loadSimpleSprite(const std::string& fileName);
        bool exist(const std::string& fileName)const;

        void generateBucket();

        const sf::Sprite& getSprite(const std::string& fileName)const;
        const sf::Sprite& getSprite(const std::string& fileName, int angle, int level)const;
};

#endif
